﻿@{
    ViewBag.Title = "SearchSongCategory";
    Layout = "~/Views/Shared/_LayoutPublic.cshtml";   
}
    <link href="@Url.Content("../../Styles/Playlist/popbox.css")" rel="stylesheet" type="text/css" />
    <script src="../../Scripts/Playlist/popbox.js" type="text/javascript"></script>
    <link href="@Url.Content("../../Styles/SongDetails.css")" rel="stylesheet" type="text/css" />    
    
<script type="text/javascript" charset='utf-8'>
    $(document).ready(function () {
        $('.popbox').popbox();
    });
</script>
    <script type="text/javascript">
        function getID(id) {
            var playlistname = document.getElementById(id).value;
            var array = id.split("-");
            var idrs = 'rs-json' + array[1];
            var rs = document.getElementById(idrs);
            $.ajax({
                url: '/playlist/addplaylist',
                dataType: 'json',
                type: "post",
                data: ({ 'playlistname': playlistname }),
                success: function (result) {
                    location.reload();
                    //                    $(rs).html(result.message);
                }
            });
        }  
    </script>
    <script type="text/javascript">       
        function addMusic(songid) {
            var plid = document.getElementById("cbx-playlist-name").value;
            if (plid != "") {
                var ans = window.confirm("Bạn chắc chắn muốn thêm bài hát này vào danh sách?");
                if (ans) {
                    $.ajax({
                        url: '/playlist/addmusic',
                        dataType: 'json',
                        type: 'post',
                        data: ({ 'songid': songid, 'plid': plid }),
                        success: function (result) {
                           
                        }
                    });
                } 
            }
        }
    </script>
<div class="content-song">   
  <div id="content-details">
<ul>
    @{
        List<ListenMusic.Song_ServiceReference.CategorySong> lst_songCategory = ViewBag.categorySong;
        List<ListenMusic.Playlist_ServiceReference.FavoritePlayList> lst_favaritesPlaylist = ViewBag.songInPlaylist;
    }  
    @foreach (ListenMusic.Song_ServiceReference.CategorySong cc in lst_songCategory)
    { 
               <li>@Html.ActionLink(@cc.SongName, "ListenPage", "Listen", new { songid = @cc.SongID, pageindex = 1 }, null)  <br />
                                <span class="sub-detail">
                                    Trình bày: <a class="singer" href="#">@cc.SingerName</a> | Lượt nghe: @cc.CountView
                                </span>
                                <div class='popbox'>
                                @if (Session["user"] == null)   
                                {
                                    <a href="#login-box" class="login-window">
                                    <img src='../../Images/Icons/add.png' alt="" width="14px" title="Thêm vào danh sách yêu thích" style='position:relative' />
                                    </a> 
                                }
                                else
                                {
                                    bool flag = true;
                                    for (int j = 0; j < lst_favaritesPlaylist.Count(); j++)
                                    {
                                        if (lst_favaritesPlaylist[j].SongID.Equals(@cc.SongID))
                                        {
                                            <a class='open1' href='#'>
                                                <img src='../../Images/Icons/check.png' alt="" style='width:14px;position:relative' />
                                            </a>  
                                            flag = false;
                                            break;
                                        }
                                    }
                                    if (flag == true)
                                    {
                                        <a class='open' rel="shareit" href='#'>
                                            <img src='../../Images/Icons/add.png' alt="" title="Thêm vào danh sách yêu thích" style='width:14px;position:relative' />
                                        </a>                       
                                    }
                                }
                                <a href="@Url.Action("dowloadfile", "dowload", new { url = @cc.SongURL })"><img src="../../Images/Icons/download.jpg" title="Tải bài hát về máy" width="16" height="16px" alt="" /></a>                  
                                  <div class='collapse'>
                                      <div class='box'>
                                        <div class='arrow'></div>
                                        <div class='arrow-border'></div>
                                        <form action="" method="post" id="subForm">
                                            <div style="margin-left:20px; margin-top:10px">
                                                <select id="cbx-playlist-name" name="cbx-playlist-name" onchange="addMusic(@cc.SongID)">
                                                    <option value="">-Chọn-</option>
                                                        @if (@Session["user"] != null)
                                                        {
                                                            foreach (ListenMusic.Playlist_ServiceReference.Playlist pl in ViewBag.playlist)
                                                            {
			                                                    <option value='@pl.PlaylistID'>@pl.PlaylistName</option>
                                                            }
                                                        }
                                                </select>
                                            <div id="rs-json@cc.SongID"></div>    
                                            </div>
                                            <div style="margin-left:20px">
                                                <input type="text" id="playlistname-@cc.SongID" name="playlistname" placeholder="Tên của laylist" style="width:90px; margin-top:10px;" /> 
                                                <a href="#" id="create-playlist" onclick="getID('playlistname-@cc.SongID')" style="font-size:small" >Tạo Playlist</a>
                                            </div>
                                          <div style="text-align:center; margin-top:10px"><a href="#" class="close">Cancel</a></div>
                                        </form>
                                      </div>
                                    </div>
                            </div>
                
        </li>     
    }
</ul>
</div>
    <div class="page_number">
            Trang:
         @for (int i = 1; i <= ViewBag.total; i++)
         {
            <a href="/song/SearchSong_byCategory?pageindex=@i&categoryid=@ViewBag.categoryID">@i</a>
         }    
    </div>
</div>